package com.zbkj.admin;

import com.zbkj.service.service.SystemConfigService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * 程序主入口
 * +----------------------------------------------------------------------
 * | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
 * +----------------------------------------------------------------------
 * | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
 * +----------------------------------------------------------------------
 * | Author: CRMEB Team <admin@crmeb.com>
 * +----------------------------------------------------------------------
 */
@EnableAsync
@EnableScheduling
@SpringBootApplication
@Configuration
@ComponentScan({"com.zbkj.admin","com.zbkj.service", "com.zbkj.common"})
@MapperScan({"com.zbkj.service.dao", "com.zbkj.admin.dao"})
@EntityScan(basePackages = "com.zbkj.common.model")
public class CrmebAdminApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(CrmebAdminApplication.class, args);
        
        // 获取 SystemConfigService 服务
        SystemConfigService systemConfigService = context.getBean(SystemConfigService.class);
        
        // ✅ 强制将上传方式设置为腾讯云 (4 = COS)
        // 无论数据库中是什么值，都将覆盖为腾讯云上传
        // 1=本地, 2=七牛, 3=OSS, 4=COS
        String tencentCosUploadType = "4";
        try {
            systemConfigService.updateOrSaveValueByName("uploadType", tencentCosUploadType);
            System.out.println("=================================================");
            System.out.println("✅ 已强制设置上传方式为: 腾讯云COS (uploadType=4)");
            System.out.println("=================================================");
        } catch (Exception e) {
            System.err.println("=================================================");
            System.err.println("❌ 强制设置上传方式失败: " + e.getMessage());
            System.err.println("=================================================");
        }
    }

}
